package com.satoken.Service;

import com.satoken.Mapper.RoleMapper;
import com.satoken.Mapper.UserMapper;
import com.satoken.Utils.SM4PasswordEncoder;
import com.satoken.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    SM4PasswordEncoder passwordEncoder;

    public boolean login(User u){
        return passwordEncoder.equls(userMapper.getUserByUsername(u.getUsername()).getPassword(),u.getPassword());
    }
    public boolean register(User u){
        String password = passwordEncoder.Encode(u.getPassword());
        return userMapper.insertUser(new User(u.getUsername(), password)) == 1 && roleMapper.insertRole(u.getUsername(), "user") == 1;
    }

    public void set_order(String username,int order_id){

    }

}
